/*
 * @Author: mikey.zhaopeng
 * @Date:   2016-05-03 17:02:57
 * @Last Modified by:   mikey.zhaopeng
 * @Last Modified time: 2016-07-13 16:17:18
 */


'use strict';
define([
    '../framework/base/baseView',
    './abTest/adQuery',
    './abTest/abTestTable',
    './abTest/abGraph'

], function(
    BaseView,
    adQueryView,
    AbTestTableView,
    AbGraphView

) {
    function me() {
        BaseView.apply(this, arguments);
        var self = this;
        this.init = function() {
            self.$root = $('.abTest-container');
            self.render();
        }

        this.render = function() {
            self.adQueryView = new adQueryView();
            self.adQueryView.init();

            self.abGraphView = new AbGraphView();

            self.abTestTableView = new AbTestTableView();
            self.abTestTableView.init();
            self.event();
        }

        this.event = function() {
            self.$root.off('queryBtnClick').on('queryBtnClick', $.proxy(self.queryBtnClick, self));
            self.$root.off('tagChanged').on('tagChanged', $.proxy(self.tagChanged, self));

        }


        this.tagChanged = function(){
            self.abTestTableView.resetListManagerSetTopVal();
        }

        /**
         * { feed被点击 }
         *
         * @param      {<type>}  e       { parameter_description }
         * @param      {<type>}  feedId    The feedId
         */
        this.feedItemClick = function(e, feedId) {
            self.filtersView = new FiltersView();
            self.toolsView = new ToolsView();
            self.abTestTableView = new AbTestTableView();

            self.filtersView.init(feedId);
            self.toolsView.init(feedId);
            self.abTestTableView.init();

        }

        /**
         * { 改变了对比维度 }
         *
         * @param      {<type>}  argument  The argument
         */
        this.changeDimension = function(e, dimension) {
            self.filtersView.hideDimension(dimension);
        }

        this.queryBtnClick = function(e) {
            var params = self.adQueryView.getParams();
            if (_.isBoolean(params) && params) {
                return;
            }

            self.abTestTableView.renderTable(params, true);

            self.abGraphView.renderGraph(params);

        }
    }
    return new me();
});
